package cn.cimoc.handler;


import cn.cimoc.model.vo.ResultVO;
import cn.cimoc.exception.CommonException;
import cn.cimoc.util.CommonUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author LGZ
 * @date 2021/10/28 9:55
 * <p>
 * 捕获所有{@link CommonException}，封装成VO类后交由{@link ResponseResultHandler}自动转换json数据
 */
@ControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(value = CommonException.class)
    @ResponseBody
    public ResultVO error(CommonException e) {
        return CommonUtils.ajaxReturn(e.getCode(), e.getMessage());
    }
}
